<template>
	<view class="box">
		<view v-if="user && user.power==1 && tabsId != '1'" class="add_user" @click="addBtnFun">
			添加+
		</view>
		<u-sticky>
			<view class="header">
				<u-tabs @click="onTabs" :list="tabsList"></u-tabs>
			</view>
		</u-sticky>
		<view class="content">
			<view class="serach_view">
				<view class="bg_fff">
					<u-input type="text" placeholder="请输入搜索内容" v-model="serachVal" @blur="searchFun" />
				</view>
			</view>
			<view v-if="tabsId == '1'" class="user_list com_width">
				<view class="user_list_item" v-for="(item,index) in userList" :key="item.uuid">
					<view class="display_flex space_between margin_bottom_l item_header">
						<view>{{item.nickName}}</view>
						<view>{{item.no}}</view>
					</view>
					<view class="item_cont">
						<view class="display_flex space_between margin_bottom_l">
							<view>手机</view>
							<view>{{item.phone}}</view>
						</view>
						<view class="display_flex space_between margin_bottom_l">
							<view>单位</view>
							<view>{{item.unitName}}</view>
						</view>
						<view class="display_flex space_between margin_bottom_l">
							<view>权限</view>
							<view>{{returnRole(item.power)}}</view>
						</view>
						<view class="display_flex space_between">
							<view>状态</view>
							<view v-if="item.state == 0">
								<up-text type="warning" text="待审核"></up-text>
							</view>
							<view v-else-if="item.state == 1">
								<up-text type="success" text="正常"></up-text>
							</view>
							<view v-else-if="item.state == 2">
								<up-text type="error" text="已过期"></up-text>
							</view>
							<view v-else-if="item.state == 3">
								<up-text type="error" text="已拒绝"></up-text>
							</view>
						</view>
					</view>
					<view class="display_flex bot_btn_list">
						<view v-if="item.state==0" @click="checkUser(item)" class="com_btn margin_left_l">审核</view>
						<view v-if="item.power==1 || item.power==2" @click="disableUser(item)" class="com_btn bg_red margin_left_l">禁用</view>
						<view v-else @click="onDelUser(item)" class="com_btn bg_red margin_left_l">删除</view>
					</view>
				</view>
			</view>
			<view v-if="tabsId == '2'" class="user_list com_width">
				<view class="user_list_item" v-for="(item,index) in unitList" :key="item.unitID">
					<view class="display_flex space_between margin_bottom_l item_header">
						<view>{{item.unitName}}</view>
						<view>{{item.unitID}}</view>
					</view>
					<view class="item_cont">
						<view class="display_flex space_between margin_bottom_l">
							<view>单位创建时间</view>
							<view>{{item.createTime}}</view>
						</view>
						<view class="display_flex space_between margin_bottom_l">
							<view>单位经营类型</view>
							<view>{{item.unitType}}</view>
						</view>
						<view class="display_flex space_between margin_bottom_l">
							<view>安全责任人</view>
							<view>{{item.safetyName}}</view>
						</view>
						<view class="display_flex space_between margin_bottom_l">
							<view>责任人联系方式</view>
							<view>{{item.safetyPhone}}</view>
						</view>
						<view class="display_flex space_between">
							<view>所属监管分组</view>
							<view>{{item.groupName}}</view>
						</view>
					</view>
					<view class="display_flex bot_btn_list">
						<button class="com_btn share_btn" :id="item?.unitID" open-type="share" type="primary">邀请</button>
						<view v-if="user && user.power==1" @click="editUnit(item)" class="com_btn margin_left_l">编辑</view>
						<view v-if="user && user.power==1" @click="delUnit(item)" class="com_btn bg_red margin_left_l">删除</view>
					</view>
				</view>
			</view>
			<view v-if="tabsId == '3'" class="user_list com_width">
				<view class="user_list_item" v-for="(item,index) in userVipList" :key="item.unitID">
					<view class="display_flex space_between margin_bottom_l item_header">
						<view>{{item.groupsName}}</view>
						<view>{{item.id}}</view>
					</view>
					<view class="item_cont">
						<view class="display_flex space_between">
							<view>所在地区：{{item.area}}</view>
							<view></view>
						</view>
					</view>
					<view class="item_cont">
						<view class="display_flex space_between">
							<view>
								<view>组长：</view>
								<view v-for="team in item.team">{{team.nickName}}【{{team.phone}}】</view>
							</view>
						</view>
					</view>
					<view class="display_flex bot_btn_list">
						<view @click="teamGroup(item)" class="com_btn margin_left_l">管理</view>
						<view @click="editUserGroup(item)" class="com_btn margin_left_l">编辑</view>
						<view @click="delUserGroup(item)" class="com_btn bg_red margin_left_l">删除</view>
					</view>
				</view>
			</view>
			<view v-if="tabsId == '4'" class="user_list com_width">
				<view class="user_list_item" v-for="(item,index) in adminList" :key="item.unitID">
					<view class="display_flex space_between margin_bottom_l item_header">
						<view>{{item.id}}</view>
						<view>{{item.groupsName}}</view>
					</view>
					<view class="item_cont">
						<view class="display_flex space_between">
							<view>区域</view>
							<view>{{item.area}}</view>
						</view>
					</view>
					<view class="display_flex bot_btn_list">
						<button class="com_btn share_btn" :id="item?.unitID" open-type="share" type="primary">邀请</button>
						<view @click="delAdmin(item)" class="com_btn bg_red margin_left_l">删除</view>
					</view>
				</view>
			</view>
			<view v-if="loading" class="loading">加载中...</view>
			<view v-if="noMore" class="no-more">已经到底啦~</view>
		</view>
		<view>
			<u-modal :show="showUnitAdd" @cancel="showUnitAdd = false" @confirm="onUnitAdd" showCancelButton :title="unitAdd.unitID?'编辑单位':'添加单位'">
				<view class="slot-content">
					<view class="slot-content-user-ops">
						<fui-input maxlength="20" required v-model="unitAdd.unitName" label="单位名称:" borderTop placeholder="请输入"></fui-input>
					</view>
					<view class="slot-content-user-ops">
						<fui-input maxlength="20" required v-model="unitAdd.safetyName" label="安全责任人:" borderTop placeholder="请输入"></fui-input>
					</view>
					<view class="slot-content-user-ops">
						<fui-input maxlength="11" number required v-model="unitAdd.safetyPhone" label="责任人联系方式:" borderTop placeholder="请输入"></fui-input>
					</view>
					<view class="slot-content-user-ops">
						<fui-input maxlength="30" :padding="['20rpx','32rpx']" required v-model="unitAdd.unitAddress" label="单位详细地址:" borderTop placeholder="请输入">
						</fui-input>
					</view>
					<view class="slot-content-user-ops">
						<fui-input maxlength="20" readonly required v-model="unitAdd.unitDistrict" label="所属行政区域:" borderTop placeholder="请选择" @click="showDistrict = true"></fui-input>
					</view>
					<view class="slot-content-user-ops">
						<fui-input maxlength="20" readonly required v-model="unitAdd.groupName" label="选择监管分组:" borderTop placeholder="请选择" @click="openGroup"></fui-input>
					</view>
					<view class="slot-content-user-ops">
						<fui-input maxlength="20" readonly required v-model="unitAdd.unitType" label="单位经营类型:" borderTop placeholder="请选择" @click="showUnitType = true"></fui-input>
					</view>
				</view>
			</u-modal>
		</view>
		<view>
			<u-modal :showCancelButton="true" @confirm="addAdminGroup" @cancel="showAdminGroup = false" :show="showAdminGroup" title="新建管理员分组">
				<view class="slot-content">
					<fui-input label="分组名" v-model="adminGroupName" borderTop placeholder="请输入分组名"></fui-input>
				</view>
			</u-modal>
		</view>
		<view>
			<u-modal :show="showUserVipGroup" @cancel="hideUserVipGroup" @confirm="addUserVipGroup" showCancelButton :title="controGroupForm.id?'编辑监管分组':'添加监管分组'">
				<view class="slot-content">
					<view class="slot-content-user-ops">
						<fui-input maxlength="20" readonly required v-model="controGroupForm.unitArea" label="所属行政区域:" borderTop placeholder="请选择" @click="showDistrict = true"></fui-input>
					</view>
					<view class="slot-content-user-ops">
						<fui-input maxlength="20" required v-model="controGroupForm.control_group" label="监管分组名称:" borderTop placeholder="请输入"></fui-input>
					</view>
				</view>
			</u-modal>
		</view>
		<view>
			<u-picker :show="showUnitType" @confirm="onUnitType" @cancel="showUnitType = false" title="单位经营类型" :columns="unitTypeColumns"></u-picker>
		</view>
		<view>
			<cityPicker :mask-close-able="maskCloseAble" :default-value="defaultValue" @confirm="oSetCity" @cancel="showDistrict = false" :visible="showDistrict" />
		</view>
		<view>
			<qianziyu-select :show="showNnitNature" type="radio" name="label" :showSearch="false" :dataLists="unitNatureList" @cancel="showNnitNature = false" @submit="onunitNature"></qianziyu-select>
		</view>
		<view>
			<qianziyu-select :show="showGroupSelect" type="radio" name="groupName" :dataLists="userVipListAll" @cancel="showGroupSelect = false" @submit="onGroupSubmit"></qianziyu-select>
		</view>
		<view>
			<qianziyu-select :show="showGroupTeam" type="checkbox" name="title" :dataLists="teamUserList" @cancel="showGroupTeam = false" @submit="onGroupTeam"></qianziyu-select>
		</view>
		<up-popup :show="showTeam" mode="center" :round="10" :closeable="true" @close="showTeam=false" :customStyle="{padding:'0 20rpx'}">
			<view class="team-box">
				<view class="team-title">组长管理</view>
				<view class="row right team-add">
					<view @click="teamUserGroup()" class="com_btn margin_left_l">添加组长</view>
				</view>
				<view v-if="teamList && teamList.length>0" class="team-list">
					<view v-for="item in teamList" class="team-item row">
						<view class="col info-col">
							<view>{{item.nickName}}</view>
							<view>手机：{{item.phone}}</view>
							<view>单位：{{item.unitName}}</view>
						</view>
						<view class="col btn-col">
							<up-button @click="delTeam(item)" type="error" size="small" text="删除"></up-button>
						</view>
					</view>
				</view>
				<view v-else class="team-list" style="text-align:center;padding-top:40rpx;">
					暂无记录
				</view>
				<view class="close-btn">
					<up-button text="关闭" @click="showTeam=false;"></up-button>
				</view>
			</view>
		</up-popup>
		<u-modal :show="showUser" @cancel="showUser=false" @confirm="submitCheckUser" showCancelButton title="账号审核">
			<view v-if="userModel" class="check-modal">
				<view class="check-box">
					<view>用户：{{userModel.nickName}}</view>
				</view>
				<view class="check-status row middle">
					<view>状态：</view>
					<up-radio-group v-model="userStatus">
						<up-radio label="通过" name="1" :customStyle="{marginRight:'8px'}"></up-radio>
						<up-radio label="拒绝" name="3" :customStyle="{marginRight:'8px'}"></up-radio>
					</up-radio-group>
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import { BASE_IP } from '@/common/http/url.js'
	import tools from '@/tools/index.js';
	import cityPicker from '@/uni_modules/piaoyi-cityPicker/components/piaoyi-cityPicker/piaoyi-cityPicker'
	export default {
		components: {
			cityPicker
		},
		data() {
			return {
				defaultValue: '',
				user: null,
				userList: [],
				unitList: [],
				userVipList: [],
				userVipListAll: [],
				adminList: [],
				controGroupForm: { control_group: null, unitArea: null, code: null },
				unitTypeColumns: [
					['甲乙类厂房', '丙类厂房', '丁戊类厂房', '甲乙类仓库', '丙类仓库', '丁戊类仓库', '办公', '普通商业', '娱乐类商业', '体育场馆', '餐饮就业', '酒店商业', '公寓商业']
				],
				unitNatureList: [{ label: "监管类", value: "2000" }, { label: "管理员类", value: "3000" }],
				unitAdd: {
					"landPlanningType": "",
					"safetyName": "",
					"safetyPhone": "",
					"unitAbbreviation": "",
					"unitAddress": "",
					"unitArea": "",
					"unitName": "",
					"unitType": "",
					"unitDistrict": "",
					"unitNature": "",
					"unitNatureId": "",
					"groupID": "",
					"groupName": "",
					"code": ""
				},
				showAdminGroup: false,
				showUserVipGroup: false,
				showUnitAdd: false,
				showDistrict: false,
				maskCloseAble: true,
				showNnitNature: false,
				showGroupSelect: false,
				showUnitType: false,
				adminGroupName: null,
				tabsList: [],
				tabsId: '1',
				currentPage: 1,
				pageSize: 15,
				serachVal: null,
				noMore: false,
				loading: false,
				showGroupTeam: false,
				teamUserList: [],
				showTeam: false,
				teamList: [],
				team: null,
				showUser: false,
				userModel: null,
				userStatus: null,
			}
		},
		onShareAppMessage(res) {
			console.log('邀请', res)
			let title = ""
			let path = ""
			if (this.tabsId == '2') {
				title = this.user.nickName + '邀请您加入他的企业！'
				path = '/pagesMine/wxLogin/wxLogin?power=3&unitId=' + res.target.id
			}
			if (this.tabsId == "3") {
				title = this.user.nickName + '邀请您加入他的监管班组！'
				path = '/pagesMine/wxLogin/wxLogin?power=2&unitId=' + this.user.unitId + '&unitGroupId=' + res.target.id
			}
			return {
				title: title,
				path: path,
				imageUrl: 'https://mp-bfea0f33-0deb-44c8-86f2-196dd6ca37a5.cdn.bspapp.com/test/head.jpg',
				success(res) {
					console.log('分享成功', res);
				},
				fail(err) {
					console.log('分享失败', err);
				}
			}
		},
		onLoad() {
			this.user = uni.getStorageSync("user")
			if (this.user.power != 1 && this.user.power != 2) {
				uni.reLaunch({ url: '/pages/user/users' });
			}
			this.setRole();
			this.getUsers();
		},
		onReachBottom() {
			// 滚动到底部触发
			if (!this.noMore && !this.loading) {
				this.currentPage++
				this.loadData()
			}
		},
		methods: {
			searchFun(e) {
				this.currentPage = 1;
				this.loading = false
				this.noMore = false
				this.loadData();
			},
			loadData() {
				if (this.tabsId == "1") {
					this.getUsers()
				} else if (this.tabsId == '2') {
					this.getUnitList()
				} else if (this.tabsId == "3") {
					this.getSuperviseGroup()
				} else if (this.tabsId == "4") {
					this.getAdminGroup()
				}
			},
			onTabs(e) {
				console.log(e)
				this.tabsId = e.id
				this.resetPage()
				this.loadData();
			},
			// -----------------用户管理相关操作-----------------
			getUsers() {
				let url = BASE_IP + "pc/user/page/v2"
				uni.request({
					header: {
						"Authorization": this.user.token
					},
					method: "POST",
					data: {
						"currentPage": this.currentPage,
						"pageSize": this.pageSize,
						"userName": this.serachVal
					},
					url: url,
					success: (res) => {
						console.log("人员列表：", res.data)
						if (res.statusCode == 200) {
							if (res.data.records.length === 0) {
								this.noMore = true
								return
							}
							this.userList = [...this.userList, ...res.data.records]
							if (res.data.records.length < this.pageSize) {
								this.noMore = true
							}
						}
					}
				})
			},
			onDelUser(item) {
				uni.showModal({
					title: "提示",
					content: "您确认要删除此用户吗",
					success: (res) => {
						if (res.confirm) {
							let user = uni.getStorageSync("user")
							let url = BASE_IP + "pc/user/remove/user/" + item.uuid
							uni.request({
								header: {
									"Authorization": user.token
								},
								method: "DELETE",
								url: url,
								success: (res) => {
									if (res.statusCode == 200) {
										uni.showToast({
											title: "删除成功",
											icon: "success"
										})
										this.resetPage()
										this.getUsers()
									}
									if (res.statusCode == 404) {
										uni.showToast({
											title: "删除失败",
											icon: "error"
										})
									}
									if (res.statusCode == 500) {
										uni.showToast({
											title: "删除失败",
											icon: "error"
										})
									}
								}
							})
						}
					}
				})
			},
			checkUser(item) {
				console.log("账号审核", item);
				this.showUser = true;
				this.userModel = item;
				this.userStatus = null;
			},
			submitCheckUser() {
				if (this.userStatus == null) {
					tools.showToast('请选择审核状态');
					return;
				}
				uni.showModal({
					title: "提示",
					content: "您确认" + (this.userStatus == 1 ? '审核通过' : '审核拒绝') + "吗",
					success: (res) => {
						if (res.confirm) {
							this.submitStatus(this.userModel.uuid, this.userStatus);
						}
					}
				})
			},
			disableUser(item) {
				uni.showModal({
					title: "提示",
					content: "您确认要禁用【" + item.nickName + "】吗",
					success: (res) => {
						if (res.confirm) {
							this.submitStatus(item.uuid, 3);
						}
					}
				})
			},
			submitStatus(uuid, status) {
				let url = BASE_IP + "pc/user/check/user/" + uuid + "/" + status
				uni.request({
					header: { "Authorization": this.user.token },
					method: "POST",
					url: url,
					success: (res) => {
						if (res.statusCode == 200) {
							uni.showToast({
								title: "操作成功",
								icon: "success"
							})
							this.showUser = false;
							this.resetPage()
							this.getUsers()
						}
						if (res.statusCode == 404) {
							uni.showToast({
								title: "删除失败",
								icon: "error"
							})
						}
						if (res.statusCode == 500) {
							uni.showToast({
								title: "删除失败",
								icon: "error"
							})
						}
					}
				})
			},
			getUnitList() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/unit/page/v2"
				uni.request({
					header: {
						"Authorization": user.token
					},
					data: {
						"currentPage": this.currentPage,
						"pageSize": this.pageSize,
						"unitName": this.serachVal,
					},
					method: "POST",
					url: url,
					success: (res) => {
						console.log("单位列表：", res.data.records)
						if (res.statusCode == 200) {
							if (res.data.records.length === 0) {
								this.noMore = true
								return
							}
							this.unitList = [...this.unitList, ...res.data.records]
							if (res.data.records.length < this.pageSize) {
								this.noMore = true
							}
						}
					}
				})
			},
			onUnitType(res) {
				console.log(res)
				this.unitAdd.unitType = res.value[0]
				this.showUnitType = false
			},
			editUnit(item) {
				console.log("编辑", item)
				this.showUnitAdd = true
				this.unitAdd = { ...item, unitID: item.unitID }
			},
			delUnit(item) {
				uni.showModal({
					title: "提示",
					content: "您确定要删除此单位吗？此操作会同时删除所有关联的用户",
					success: (res) => {
						if (res.cancel) {}
						if (res.confirm) {
							let user = uni.getStorageSync("user")
							let url = BASE_IP + "pc/unit/" + item.unitID
							uni.request({
								header: {
									"Authorization": user.token
								},
								method: "DELETE",
								url: url,
								success: (res) => {
									console.log("单位删除回调：", res)
									if (res.statusCode == 200) {
										uni.showToast({
											title: "删除成功",
											icon: "success"
										})
										this.resetPage()
										this.getUnitList()
										return;
									}
									uni.showToast({
										title: "删除失败",
										icon: "error"
									})
								}
							})
						}
					}
				})
			},
			onunitNature(e) {
				console.log("企业类型选择", e)
				this.unitAdd.unitNature = e.label
				this.unitAdd.unitNatureId = e.value
				this.showNnitNature = false
			},
			onGroupSubmit(e) {
				console.log("分组选择", e)
				this.unitAdd.groupID = e.id
				this.unitAdd.groupName = e.groupName
				this.showGroupSelect = false
			},
			onUnitAdd() {
				if (this.unitAdd.unitName == "") {
					uni.showToast({
						title: "单位名称为空",
						icon: "error"
					})
					return
				}
				if (this.unitAdd.safetyName == "") {
					uni.showToast({
						title: "安全责任人为空",
						icon: "error"
					})
					return
				}
				if (this.unitAdd.safetyPhone == "") {
					uni.showToast({
						title: "联系方式为空",
						icon: "error"
					})
					return
				}
				if (this.unitAdd.unitAddress == "") {
					uni.showToast({
						title: "单位地址为空",
						icon: "error"
					})
					return
				}
				if (this.unitAdd.unitDistrict == "") {
					uni.showToast({
						title: "所属区域为空",
						icon: "error"
					})
					return
				}
				if (this.unitAdd.unitNature == "") {
					// uni.showToast({
					// 	title: "企业类型为空",
					// 	icon: "error"
					// })
					// return
				}
				if (this.unitAdd.groupID == "") {
					uni.showToast({
						title: "单位分组信息为空",
						icon: "error"
					})
					return
				}
				if (this.unitAdd.unitType == "") {
					uni.showToast({
						title: "单位经营类型为空",
						icon: "error"
					})
					return
				}
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/unit/insert"
				if (this.unitAdd.unitID != null) {
					url = BASE_IP + "pc/unit/update"
				}
				uni.request({
					header: { "Authorization": user.token },
					data: this.unitAdd,
					method: "POST",
					url: url,
					success: (res) => {
						if (res.statusCode == 200) {
							uni.showToast({
								title: "保存成功",
								icon: "success"
							})
							this.resetPage()
							this.getUnitList()
						}
						if (res.statusCode == 500) {
							uni.showToast({
								title: "添加失败",
								icon: "error"
							})
							return
						}
						if (res.statusCode == 404) {
							uni.showToast({
								title: "添加失败",
								icon: "error"
							})
							return
						}
					}
				})
				this.showUnitAdd = false
			},
			openGroup() {
				this.showGroupSelect = true;
				this.getSuperviseAllGroup();
			},
			// -----------------监管分组相关操作-----------------
			getSuperviseGroup() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/group/page/supervise"
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					data: {
						"currentPage": this.currentPage,
						"pageSize": this.pageSize,
						"unitGroupName": this.serachVal
					},
					url: url,
					success: (res) => {
						console.log("监管分组：", res.data)
						if (res.statusCode == 200) {
							if (res.data.records.length === 0) {
								this.noMore = true
								return
							}
							this.userVipList = [...this.userVipList, ...res.data.records]
							if (res.data.records.length < this.pageSize) {
								this.noMore = true
							}
						}
					}
				})
			},
			hideUserVipGroup() {
				this.showUserVipGroup = false
			},
			delUserGroup(item) {
				console.log("删除", item)
				uni.showModal({
					title: "提示",
					content: "您确认要删除此分组吗",
					success: (res) => {
						if (res.confirm) {
							let user = uni.getStorageSync("user")
							let url = BASE_IP + "pc/group/deleteById/" + item.id
							uni.request({
								header: { "Authorization": user.token },
								method: "DELETE",
								url: url,
								success: (res) => {
									if (res.statusCode == 200) {
										uni.showToast({ title: "删除成功", icon: "success" })
										this.resetPage()
										this.getSuperviseGroup()
									}
									if (res.statusCode == 404) {
										uni.showToast({ title: "删除失败", icon: "error" })
									}
									if (res.statusCode == 500) {
										uni.showToast({ title: "删除失败", icon: "error" })
									}
								}
							})
						}
					}
				})
			},
			editUserGroup(item) {
				console.log("编辑", item)
				this.showUserVipGroup = true
				this.controGroupForm = {
					control_group: item.groupsName,
					unitArea: item.area,
					code: item.code,
					id: item.id
				}
				this.defaultValue = item.code;
			},
			teamGroup(item) {
				console.log('组长管理', item);
				this.team = item;
				this.showTeam = true;
				this.loadTeam();
			},
			loadTeam() {
				tools.showLoading();
				uni.request({
					header: { "Authorization": this.user.token },
					method: "GET",
					url: BASE_IP + "pc/group/page/teamList/" + this.team.id,
					success: (res) => {
						console.log("组长：", res.data)
						if (res.statusCode == 200) {
							let list = [];
							for (let i in res.data.data) {
								list.push(JSON.parse(res.data.data[i]));
							}
							this.teamList = list;
							tools.hideLoading();
						}
					}
				})
			},
			teamUserGroup() {
				this.showGroupTeam = true;
				this.showTeam = false;
				tools.showLoading();
				uni.request({
					header: { "Authorization": this.user.token },
					method: "GET",
					url: BASE_IP + "pc/group/page/teamUserList/" + this.team.id,
					success: (res) => {
						console.log("组长列表：", res.data)
						if (res.statusCode == 200) {
							let list = [];
							for (let i in res.data.data) {
								list.push(JSON.parse(res.data.data[i]));
							}
							this.teamUserList = list;
							tools.hideLoading();
						}
					}
				})
			},
			onGroupTeam(e) {
				let ids = e.map(item => item.uuid);
				console.log('选择组长', e, ids);
				if (ids && ids.length > 0) {
					uni.request({
						header: { "Authorization": this.user.token },
						data: { ids: ids.join(',') },
						method: 'POST',
						url: BASE_IP + "pc/group/page/teamSave/" + this.team.id,
						success: (res) => {
							if (res.statusCode == 200) {
								uni.showToast({
									title: "保存成功",
									icon: "success"
								})
								this.showGroupTeam = false;
								this.teamGroup(this.team);
								this.resetPage();
								this.getSuperviseGroup();
							}
							if (res.statusCode == 500) {
								uni.showToast({
									title: "添加失败",
									icon: "error"
								})
								return
							}
							if (res.statusCode == 404) {
								uni.showToast({
									title: "添加失败",
									icon: "error"
								})
								return
							}
						}
					})
				}
			},
			delTeam(item) {
				console.log("删除组长", item)
				let _this = this;
				uni.showModal({
					title: "提示",
					content: "您确认要删除【" + item.nickName + "】的组长身份吗",
					success: (res) => {
						if (res.confirm) {
							uni.request({
								header: { "Authorization": this.user.token },
								method: "DELETE",
								url: BASE_IP + "pc/group/page/teamDelete/" + item.id,
								success: (res) => {
									if (res.statusCode == 200) {
										uni.showToast({ title: "删除成功", icon: "success" })
										setTimeout(() => {
											_this.loadTeam();
											_this.resetPage();
											_this.getSuperviseGroup();
										}, 1000)
									}
									if (res.statusCode == 404) {
										uni.showToast({ title: "删除失败", icon: "error" })
									}
									if (res.statusCode == 500) {
										uni.showToast({ title: "删除失败", icon: "error" })
									}
								}
							})
						}
					}
				})
			},
			addUserVipGroup() {
				if (this.controGroupForm.control_group == "") {
					uni.showToast({
						title: "请填写监管分组名称",
						icon: "error"
					})
					return
				}
				if (this.controGroupForm.unitArea == "") {
					uni.showToast({
						title: "请填写所属区域",
						icon: "error"
					})
					return
				}
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/group/save/control/group";
				let data = {
					"type": "2000",
					"code": this.controGroupForm.code,
					"area": this.controGroupForm.unitArea,
					"groupName": this.controGroupForm.control_group,
				}
				if (this.controGroupForm.id) {
					data.id = this.controGroupForm.id
				}
				uni.request({
					header: { "Authorization": user.token },
					method: "POST",
					data: data,
					url: url,
					success: (res) => {
						console.log("新增监管分组：", res.data)
						if (res.statusCode == 200) {
							uni.showToast({ title: "保存成功", icon: "success" })
							this.userVipList = [];
							this.serachVal = ""
							this.resetPage()
							this.getSuperviseGroup()
							this.showUserVipGroup = false
						}
					}
				})
			},
			// -----------------管理员分组相关操作-----------------
			getAdminGroup() {
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/group/page/admin"
				uni.request({
					header: {
						"Authorization": user.token
					},
					method: "POST",
					data: {
						"currentPage": this.currentPage,
						"pageSize": this.pageSize,
						"unitGroupName": this.serachVal
					},
					url: url,
					success: (res) => {
						console.log("管理员分组查询接口：", res.data.records)
						if (res.statusCode == 200) {
							if (res.data.records.length === 0) {
								this.noMore = true
								return
							}
							this.adminList = [...this.adminList, ...res.data.records]
							if (res.data.records.length < this.pageSize) {
								this.noMore = true
							}
						}
					}
				})
			},
			delAdmin(item) {
				console.log(item)
			},
			addAdminGroup() {
				if (this.adminGroupName == "") {
					uni.showToast({
						title: "分组名未添加",
						icon: "error"
					})
					return
				}
				let url = BASE_IP + "pc/group/insertGroup/" + this.adminGroupName + "/" + this.user.uuid
				let user = uni.getStorageSync("user")
				uni.request({
					header: {
						"Authorization": user.token
					},
					url: url,
					method: "POST",
					success: (res) => {
						if (res.statusCode == 200) {
							uni.showToast({
								title: "添加成功",
								icon: "success"
							})
							this.adminList = [];
							this.resetPage()
							this.getAdminGroup()
							return;
						}
						uni.showToast({
							title: "添加失败",
							icon: "none"
						})
					}
				})
				this.showGroup = false
			},
			setRole() {
				let user = uni.getStorageSync("user")
				console.log("当前角色：", user.power)
				// 管理员
				if (user.power == 1) {
					this.tabsList = [{ name: '用户管理', id: "1" }, { name: '企业分组', id: "2" }, { name: '监管分组', id: "3" }, { name: '管理员分组', id: "4" }];
				}
				// 操作工
				if (user.power == 2) {
					this.tabsList = [{ name: '用户管理', id: "1" }, { name: '企业分组', id: "2" }];
				}
			},
			returnRole(power) {
				if (power == 1) {
					return '系统管理员';
				} else if (power == 2) {
					return '监管人员';
				} else if (power == 3) {
					return '操作人员';
				} else {
					return '未知角色';
				}
			},
			resetPage() {
				this.currentPage = 1;
				this.serachVal = ""
				this.loading = false
				this.noMore = false
				this.userList = [];
				this.unitList = [];
				this.userVipList = [];
				this.adminList = [];
			},
			oSetCity(e) {
				console.log('sc', e)
				if (this.showDistrict == true) {
					this.unitAdd.unitDistrict = e.areaName
				}
				if (this.showUserVipGroup == true) {
					this.controGroupForm.code = e.code;
					this.controGroupForm.unitArea = e.areaName
				}
				this.showDistrict = false
			},
			// 监管分组所有数据查询接口
			getSuperviseAllGroup() {
				tools.showLoading();
				let user = uni.getStorageSync("user")
				let url = BASE_IP + "pc/group/page/superviseAll"
				uni.request({
					header: { "Authorization": user.token },
					method: "GET",
					url: url,
					success: (res) => {
						console.log("监管分组查询接口：", res.data)
						if (res.statusCode == 200) {
							let list = [];
							for (let i in res.data.data) {
								list.push(JSON.parse(res.data.data[i]));
							}
							this.userVipListAll = list;
							tools.hideLoading();
						}
					}
				})
			},
			addBtnFun() {
				if (this.tabsId == "2") {
					this.showUnitAdd = true
				} else if (this.tabsId == "3") {
					this.controGroupForm = { control_group: "", unitArea: "", code: "" }
					this.showUserVipGroup = true
				} else if (this.tabsId == "4") {
					this.showAdminGroup = true
				} else if (this.tabsId == 4) {
					this.showAddDevice = true
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		box-sizing: border-box;

		.bg_red {
			background: red;
		}

		.share_btn {
			margin: 0 !important;
			background: #49A0FF;
			padding: 18rpx 40rpx !important;
			font-size: 28rpx !important;
			border-radius: 9rpx !important;
		}

		.loading,
		.no-more {
			text-align: center;
			padding: 40rpx;
			color: #999;
		}

		.add_user {
			position: fixed;
			right: 10rpx;
			bottom: 20%;
			border-radius: 50%;
			background: #49A0FF;
			color: #fff;
			width: 100rpx;
			height: 100rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			z-index: 999;
		}

		.header {
			background: #fff;
		}

		.content {
			background: rgba(215, 220, 233, .5);
			padding-top: 20rpx;

			.serach_view {
				padding: 0 30rpx 20rpx 30rpx;
			}

			.user_list {
				.user_list_item {
					border-radius: 12rpx;
					box-shadow: 0rpx -1rpx 10rpx 0rpx rgba(102, 102, 102, 0.1);
					background: #fff;
					margin-bottom: 20rpx;

					.item_header {
						border-bottom: 1px solid #EEEEEE;
						padding: 20rpx 30rpx;
					}

					.item_cont {
						padding: 10rpx 30rpx;

						.item {}
					}

					.bot_btn_list {
						padding: 20rpx 30rpx;
						justify-content: flex-end;

					}
				}
			}

		}
	}

	.team-box {
		width: 650rpx;
		padding: 20rpx 0;
	}

	.team-title {
		font-size: 36rpx;
		font-weight: bold;
		text-align: center;
		margin-bottom: 30rpx;
	}

	.team-add {
		margin-bottom: 20rpx;
		padding-right: 40rpx;
		justify-content: flex-end;
	}

	.team-list {
		max-height: 40vh;
		overflow-y: auto;
		border-top: 1px solid #eee;
	}

	.team-item {
		border-bottom: 1px solid #eee;
		padding: 20rpx;
		align-items: center;
		justify-content: space-between;
		flex-wrap: wrap;
	}

	.info-col {
		flex: 1;
	}

	.btn-col {
		display: flex;
		justify-content: flex-end;
	}

	.close-btn {
		margin-top: 40rpx;
	}

	.check-modal {}

	.check-box {
		line-height: 50rpx;
	}

	.check-status {
		margin-top: 20rpx;
	}
</style>